<?php

class Quad_Data_Version extends Quad_Data_Abstract {
	
	public $major;
	public $minor;
	public $revision;
	
	public function __construct($no = '') {
		$this->raw = $no;
		list ($this->major, $this->minor, $this->revision) = explode('.', trim($no));
	}
	
	public static function create($no) {
		return new self($no);
	}
	
	public function isValid() {
		return !$this->isEmpty();
	}

	public function format() {
		$out = $this->major;
		$out .= $this->minor ? '.' . $this->minor : '';
		$out .= $this->revision ? '.' . $this->revision : '';
		return $out;
	}

	public function compare($ver, $operator = null) {
		$ver = (string) $ver;
		return version_compare((string) $this, $ver, $operator);
	}
	
	public function isAtLeast($ver) {
		return $this->compare($ver, '>=');
	}
	
	public function isGreaterThanOrEqual($ver) {
		return $this->compare($ver, '>=');
	}	
	
	public function isLessThan($ver) {
		return $this->compare($ver, '<');
	}
	
	public function isLessThanOrEqual($ver) {
		return $this->compare($ver, '<=');
	}	
	
	public function isGreaterThan($ver) {
		return $this->compare($ver, '>');
	}
	
	public function isNotEqual($ver) {
		return $this->compare($ver, '!=');
	}
	
	public function equals($ver) {
		return $this->compare($ver, '==');
	}
	
	public function isEqual($ver) {
		return $this->compare($ver, '==');
	}	
		
}